package Simple;

import java.util.Scanner;

/**
 * 把0到2^(n+m)-1的数写成2^n * 2^m的矩阵，使得位置相邻两数的二进制表示只有一位之差。
 * 
 * 所有数都是由m位的Gray码和n位Gray码拼接而成，需要用左移操作和or运算完成.
 * gray码生成  x xor (x shr 1)
 * http://www.matrix67.com/blog/archives/266
 * @author YC
 *
 */

public class matrix_of_2mn {
	
	/**
	 * Change a integer to n length binary number
	 * such as n=3,length=4, return 0011
	 * @param n		the integer needed to be changed
	 * @param length		the length
	 * @return	a binary string
	 */
	public static String tobinary(int n, int length){
		
		String to_return ="";
		boolean minus_number = false;
		int templength = 0;
		
		//if n is minus number 
		if(n<0) {
			minus_number = true;
			n=n*(-1) + 1;
		}
		while(n>0){
			if(n%2==0) to_return = "0"+ to_return;
			else to_return ="1"+to_return;
			templength++;
			n /= 2;
		}
		
		//add the additional space like 0-->000
		for (int i = 0; i < length-templength; i++) {
			if(minus_number)
				to_return = "1" + to_return;
			else to_return = "0" + to_return;
		}
		return to_return.trim();
		
	}
	
	public static void main (String[] args){
		System.out.println("Input m");
		Scanner in = new Scanner(System.in);
		int m = Integer.parseInt(in.nextLine());
		System.out.println("Input n");
		in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		int[][] matrix = new int[2<<(m-1)][2<<(n-1)];
		
		for(int i=0;i<(2<<(m-1));i++){
			int temp1 = (i ^ (i>>1))<<n;
			for(int j=0;j<(2<<(n-1));j++){
				int temp2 = (j^(j>>1));
				temp2 |=temp1;
				matrix[i][j] = temp2;
			}
		}
		
		for(int i=0;i<(2<<(m-1));i++){
			for(int j=0;j<(2<<(n-1));j++)
				System.out.print(tobinary(matrix[i][j],m+n)+" ");
			System.out.println();
		}
		
//		System.out.println(2<<(m-1));
//		
//		System.out.println(tobinary(3, 3));
//		System.out.println(Integer.toBinaryString(-3));
	
	
	
	}

	
}
